package Assignment;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.Arrays;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class World extends JPanel{
    public static final int WIDTH = 641;
    public static final int HEIGHT = 479;

    Battleship ship = new Battleship();
    private SeaObject[] submarines ={};
    private Mine[] mine = {};
    private Bomb[] bomb = {};

    public int subEnterIndex = 0;

    public SeaObject nextSummarine(){
        Random rand = new Random(100);
        int type = rand.nextInt();
        if(type < 40){
            return new MineSubmarine();
        }if(type < 70){
            return new ObserveSubmarine();
        }else{
            return new TorpedoSubmarine();
        }
    }

    public void submarinesEnterAction(){
        subEnterIndex++;
        if(subEnterIndex%40 ==0){
            SeaObject obj = nextSummarine();

        }
    }
    public void action(){
        KeyAdapter k = new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    Bomb obj = ship.shootBomb();
                    bomb = Arrays.copyOf(bomb,bomb.length+1);
                    bomb[bomb.length-1] = obj;
                }
            }
        };

    }



    public static void main(String[] args) {
        JFrame frame =new JFrame();
        cn.tedu.submarine.World world = new cn.tedu.submarine.World();//加载world类的方法区
        world.setFocusable(true);
        frame.add(world);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(WIDTH+16,HEIGHT+39);//窗口尺寸
        //frame.setSize(479+16,HEIGHT+39);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        world.action();

    }
}
